package com.audaque.springboot.foshanupload.authcore.controller;

/**
 * @author zgb
 * @desc ...
 * @date 2022-06-16 15:34:45
 */


import com.audaque.springboot.foshanupload.authcore.model.currentUser.TransmittableThreadLocalCurrentUser;
import com.audaque.springboot.foshanupload.core.result.R;

import com.audaque.springboot.foshanupload.authcore.service.inface.LoginService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * 登录控制器
 *
 * @author zgb
 */

@Slf4j
public abstract class AbstractAuthenticationController {
    @Autowired
    private LoginService loginService;

     //认证请求的方式必须为POST
    @PostMapping("/login")
    public void login(HttpServletRequest request, HttpServletResponse response, HttpSession httpSession, @RequestParam(required = true) String username, @RequestParam(required = true) String password) throws Exception {
        //不响应，要响应则在拦截器或过滤器响应
        log.debug("不响应，要响应则在拦截器或过滤器响应");
    }


    @GetMapping("/logout")
    public void logout(HttpServletRequest request, HttpSession httpSession) {
        //不响应，要响应则在拦截器或过滤器响应
        log.debug("不响应，要响应则在拦截器或过滤器响应");
    }

    @GetMapping("/getSessionId")
    public String getSessionId(HttpServletRequest request, HttpSession httpSession) {
        return loginService.getSessionId(request, httpSession);
    }

    @GetMapping("/getUserId")
    public String getUserId(HttpServletRequest request, HttpSession httpSession) {
        return loginService.getUserId();
    }

    @GetMapping("/getCurrentUser")
    public TransmittableThreadLocalCurrentUser getCurrentUser(HttpServletRequest request, HttpSession httpSession) {
        return loginService.getCurrentUser();
    }

    @GetMapping("/checkLogin")
    public R checkLogin(HttpServletRequest request, HttpSession httpSession) {
        return loginService.checkLogin();
    }


}
